package dao.Impl;

import dao.BaseDao;
import dao.ShopDao;
import model.entity.Shop;

public class ShopDaoImpl extends BaseDao implements ShopDao {
    @Override
    public Shop getShop() {
        Shop shop=new Shop();
        String sql="select * from shop;";
        try {
            pstmt= conn.prepareStatement(sql);
            pstmt.executeQuery();
            rs=pstmt.getResultSet();
            while (rs.next()){
                shop.setId(rs.getInt("id"));
                shop.setShop_address(rs.getString("shop_address"));
                shop.setShop_name(rs.getString("shop_name"));
                shop.setOpening_time(rs.getTime("opening_time"));
                shop.setClosing_time(rs.getTime("closing_time"));
                shop.setStatus(rs.getInt("status"));
            }
        } catch (Exception e) {
            System.out.println("查询商店信息错误："+e);
        }
        return shop;
    }

    @Override
    public void updateStatus(int id, int status) {
        String sql="update shop set status=? where id=?";
        try{
            pstmt= conn.prepareStatement(sql);
            pstmt.setInt(1,status);
            pstmt.setInt(2,id);
            pstmt.executeUpdate();
            System.out.println("修改餐厅状态成功");
        } catch (Exception e) {
            System.out.println("修改餐厅状态失败："+e);
        }
    }

    @Override
    public void update(Shop shop) {
        String sql="update shop set shop_name=?,shop_address=? where id=?";
        try{
            pstmt= conn.prepareStatement(sql);
            pstmt.setString(1,shop.getShop_name());
            pstmt.setString(2,shop.getShop_address());
            pstmt.setLong(3,shop.getId());
            pstmt.executeUpdate();
            System.out.println("修改餐厅信息成功");
        } catch (Exception e) {
            System.out.println("修改餐厅信息失败："+e);
        }
    }
}
